package com.longge;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-06-05 00:05
 */
public class ConvertBiNode {
    private List<Integer> arr = new ArrayList<Integer>();

    public TreeNode convertBiNode(TreeNode root) {

        dfs(root);
        TreeNode dummy = new TreeNode(0), cur = dummy;
        for (Integer value : arr) {
            cur.right = new TreeNode(value);
            cur = cur.right;
        }
        return dummy.right;
    }

    private void dfs(TreeNode root) {
        if (root == null) return;
        dfs(root.left);
        arr.add(root.val);
        dfs(root.right);
    }
}
